<template>
  <div class="content-block">
    <div class="info-head">{{ title }}</div>
    <div class="info-content padding">
      <el-table
        v-loading="loading" class="table"
        :data="lists"
        :header-cell-style="{
          backgroundColor: themeColor,
          color: 'white'
        }"
      >
        <el-table-column v-for="column in columns" :key="column.prop" v-bind="column"></el-table-column>
      </el-table>
<!--      <el-pagination-->
<!--        class="pagination" layout="total,prev,pager,next"-->
<!--        hide-on-single-page background-->
<!--        :current-page.sync="pagination.pageNumber" :page-size="pagination.pageSize"-->
<!--        :total="pagination.total"-->
<!--        @current-change="getLists"-->
<!--      ></el-pagination>-->
    </div>
  </div>
</template>

<script>
import { uuid } from '@/utils'

export default {
  name: 'grid-item-two',
  props: {
    title: String
  },
  data () {
    return {
      loading: false,
      lists: [],
      columns: [
        { label: '区域', prop: 'area' },
        { label: '综合能源消费量控制目标（万吨标准煤）', prop: 'comprehensive' },
        { label: '综合能源消费量实际发生（万吨标准煤）', prop: 'comprehend' },
        { label: '强度控制目标（%）', prop: 'control' },
        { label: '强度实际发生（千克标准煤/万元）', prop: 'controlled' },
      ],
      pagination: {
        pageNumber: 1,
        pageSize: 5,
        total: 0
      }
    }
  },
  computed: {
    themeColor () {
      return this.$store.state.user.theme
    },
    districts () {
      return this.$store.getters['user/districts']
    },
  },
  mounted () {
    this.getLists()
  },
  methods: {
    getLists () {
      const rand = (n = 100) => (Math.random() * n).toFixed(2)
      this.loading = true
      // TODO
      return new Promise((resolve) => {
        resolve()
        this.pagination.total = 100
        this.loading = false
        this.lists = this.districts.map(v => ({
          id: uuid(),
          area: v.name,
          comprehensive: rand(),
          comprehend: rand(),
          control: rand(),
          controlled: rand(),
        }))
      })
    }
  }
}
</script>

<style scoped>

</style>
